package cn.melonlib.cores.jpa.model.bean.impl;

import cn.melonlib.cores.commons.comp.enums.OrderByType;
import cn.melonlib.cores.commons.comp.enums.QueryType;
import cn.melonlib.cores.commons.model.entity.IEntity;
import cn.melonlib.cores.jpa.model.bean.OffsetQuery;
import cn.melonlib.objects.maps.JsonMap;
import org.intellij.lang.annotations.Language;

import java.io.Serializable;
import java.util.List;

public class OffsetQueryImpl extends DefaultQuery implements OffsetQuery {

    public OffsetQueryImpl(@Language("HQL") String content, List<? extends Serializable> params, long offset , long limit) {
        this(content, params,offset,limit, QueryType.HIBERNATE_QL);
    }

    public OffsetQueryImpl(@Language("HQL")String content, List<? extends Serializable> params, long offset , long limit, JsonMap<OrderByType> orderBy, QueryType queryType) {
        super(content, params,orderBy, queryType);
        this.offset=offset;
        this.limit=limit;
    }
    public OffsetQueryImpl(@Language("HQL")String content, List<? extends Serializable> params, long offset , long limit,  QueryType queryType) {
        this(content, params,offset,limit, JsonMap.<OrderByType>createMap().append("id",OrderByType.ASC), queryType);
    }

    public OffsetQueryImpl(Class<? extends IEntity<? extends Serializable>> entityType, JsonMap<JsonMap<Object>> filter, JsonMap<OrderByType> orderBy, long offset , long limit){
        super(entityType,filter,orderBy);
        this.offset=offset;
        this.limit=limit;
    }
    public OffsetQueryImpl(Class<? extends IEntity<? extends Serializable>> entityType, JsonMap<JsonMap<Object>> filter, long offset , long limit){
        this(entityType,filter, JsonMap.<OrderByType>createMap().append("id",OrderByType.ASC),offset,limit);
    }

    private final long limit;

    private final long offset;

    @Override
    public long getLimit() {
        return this.limit;
    }

    @Override
    public long getOffset() {
        return this.offset;
    }
}
